export default {
    state: () => ({
        isLogin: false,
        userInfo: {
            auth_status: 0,
            money: '',
            phone: '',
            status: 0,
            vip: 0,
            vip_expire_time: 0,
            wechat_info: {
                head_img_url: '',
                nickname: ''
            },
            guide_status: '',
            level_money: ''
        },
        status: {
            shop_verify: 0,
            shop_verify_fail_reason: '',
            deposit_status: 0,
            company_verify: 0,
            company_verify_fail_reason: ''
        },
        // 判断来源,方便seo优化追踪来源
        sales: {
            referrer_channel: '',
            referrer_platform: ''
        }
    }),
    mutations: {
        SET_IS_LOGIN(state, isLogin) {
            state.isLogin = isLogin
        },
        SET_USER_INFO(state, userInfo) {
            state.userInfo = userInfo
        },
        RESET_USER_INFO(state, userInfo) {
            state.userInfo = {
                auth_status: 0,
                money: '',
                phone: '',
                status: 0,
                vip: 0,
                vip_expire_time: 0,
                wechat_info: {
                    head_img_url: '',
                    nickname: ''
                },
                guide_status: '',
                level_money: ''
            }
        },
        SET_USER_STATUS(state, status) {
            state.status = status
        },
        SET_SALES(state, { channel, platform }) {
            state.sales.referrer_channel = channel
            state.sales.referrer_platform = platform
        }
    },
    getters: {
        isVip: (state) => {
            const currTime = Date.parse(new Date()) / 1000

            return (
                state.userInfo.vip > 0 &&
                state.userInfo.vip_expire_time > currTime
            )
        }
    }
}
